using System;
using System.Collections.Generic;
using System.Text;
using Firestarter.DB.Schema.BO;
using FireStarterModeller.BO;

namespace FireStarter.CodeGeneration
{
    public class WinProjectTemplateLoader : TemplateLoader
    {
        public string GetUiManagerWin(string namespaceName, string uiBaseProjectName, string uiwinProjectName, string applicationName)
        {
            string fileName = "";
            string fileContents;
            if (!loadFromFile(fileName, out fileContents))
            {
                fileContents = Templates.Win_UIManagerWin_cs;
            }
            SetNamespaceTag(ref fileContents, namespaceName);
            fileContents = fileContents.Replace("<<UIBASEPROJECT_NAME>>", uiBaseProjectName);
            fileContents = fileContents.Replace("<<UIWINPROJECT_NAME>>", uiwinProjectName);
            fileContents = fileContents.Replace("<<APPLICATION_NAME>>", applicationName);

            return fileContents;
        }

        public string GetProgramForDual(string namespaceName, string projectName, string projectVersion, string applicationName, string boProjectName)
        {
            string fileName = "";
            string fileContents;
            if (!loadFromFile(fileName, out fileContents))
            {
                fileContents = Templates.Win_Program_cs;
            }
            if (String.IsNullOrEmpty(projectVersion))
            {
                projectVersion = "v1.0";
            }
            SetNamespaceTag(ref fileContents, namespaceName);
            fileContents = fileContents.Replace("<<PROJECT_NAME>>", projectName);
            fileContents = fileContents.Replace("<<PROJECT_VERSION>>", projectVersion);
            fileContents = fileContents.Replace("<<APPLICATION_NAME>>", applicationName);
            fileContents = fileContents.Replace("<<BOPROJECT_NAME>>", boProjectName);
            return fileContents;
        }

        public string GetAppConfig(DMSolution modelSolution)
        {
            string fileName = "";
            string fileContents;
            if (!loadFromFile(fileName, out fileContents))
            {
                fileContents = Templates.Win_App_config;
            }
            DatabaseConnectionInfo databaseConnectionInfo = modelSolution.GenerationSettings.DatabaseConnection;
            if (databaseConnectionInfo == null)
            {
                databaseConnectionInfo = new DatabaseConnectionInfo {Vendor = "InMemory"};
            }

            databaseConnectionInfo.Parent = modelSolution;
            return GetGeneratedTemplate(fileContents, databaseConnectionInfo);
        }

        public string GetProgramForWinOnly(string namespaceName, string projectName, string projectVersion, string applicationName, string boProjectName)
        {
            string fileName = "";
            string fileContents;
            if (!loadFromFile(fileName, out fileContents))
            {
               fileContents = Templates.Win_Program_WinOnly_cs;
            }
            if (String.IsNullOrEmpty(projectVersion))
            {
                projectVersion = "v1.0";
            }
            SetNamespaceTag(ref fileContents, namespaceName);
            fileContents = fileContents.Replace("<<PROJECT_NAME>>", projectName);
            fileContents = fileContents.Replace("<<PROJECT_VERSION>>", projectVersion);
            fileContents = fileContents.Replace("<<APPLICATION_NAME>>", applicationName);
            fileContents = fileContents.Replace("<<BOPROJECT_NAME>>", boProjectName);
            return fileContents;
        }
    }
}
